import tinymce from 'tinymce/tinymce'
import store from '@/store'
import { save } from '@/api'
import { getStrData2Save } from '@/utils/save'
import { emit } from '@/utils/helpers'

tinymce.PluginManager.add('collaborate', function (editor) {
  return (
    editor.ui.registry.addMenuItem('collaborate', {
      text: '多人协同',
      async onAction() {
        // 只有主编需要更新大纲接口
        if (store.getters.isChief) {
          await save(getStrData2Save())
        }
        emit('show-collaborate-dialog')
      }
    }),
    {
      getMetadata: function () {
        return {
          name: '多人协同',
          url: 'http://sfrj.cn'
        }
      }
    }
  )
})
